CONTENTS | INDEX | PREV | NEXT
strpbrk
NAME
strpbrk - search for specific character(s) (tokens) in string
SYNOPSIS
char *ptr = strpbrk(s, toks)
const char *s;
char *toks;
FUNCTION
Searches the string s for any character in the string toks. For
example, when searching for whitespace in s, toks would contain the
space and tab character.
If no character in s matches any character in toks then NULL is
returned.
EXAMPLE
#include <stdio.h>
#include <string.h>
#include <assert.h>
main()
{
char *s = "This tis a test";
char *ptr;
ptr = strpbrk(s, " t");
assert(ptr == s + 4);
ptr = strpbrk(ptr + 1, " t");
assert(ptr == s + 5);
ptr = strpbrk(ptr + 1, " t");
assert(ptr == s + 6);
ptr = strpbrk(ptr + 1, " t");
assert(ptr == s + 9);
ptr = strpbrk(ptr + 1, "xyz"); /* doesn't find 'm */
assert(ptr == NULL);
return(0);
}
INPUTS
char *s; pointer to string to scan
char *toks; pointer to string containing tokens to scan for
RESULTS
char *ptr; pointer to point in s where the character matches
any character in toks, or NULL if s was exhausted.
SEE ALSO
strtok